<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Customer Report</title>
  <style>
    table {
      width: 100%;
      border-collapse: collapse;
    }
    th, td {
      border: 1px solid #dddddd;
      text-align: left;
      padding: 8px;
    }
    th {
      background-color: #f2f2f2;
    }
    tr:nth-child(even) {
      background-color: #f9f9f9;
    }
  </style>
</head>
<body>
<h1>Customer Report</h1>
<table id="customerTable">
  <thead>
  <tr>
    <th>ID</th>
    <th>Username</th>
    <th>Email</th>
    <th>User Type</th>
    <th>Telephone</th>
  </tr>
  </thead>
  <tbody>
  <!-- 数据将插入到这里 -->
  </tbody>
</table>

<script>
  // 从后端获取客户数据
  fetch('https://localhost:8088/api/customers')  // 调用后端报表接口
          .then(response => response.json())
          .then(data => {
            const tableBody = document.querySelector('#customerTable tbody');
            data.forEach(customer => {
              const row = document.createElement('tr');
              row.innerHTML = `
                        <td>${customer.id}</td>
                        <td>${customer.username}</td>
                        <td>${customer.email}</td>
                        <td>${customer.userType}</td>
                        <td>${customer.telephone}</td>
                    `;
              tableBody.appendChild(row);
            });
          })
          .catch(error => {
            console.error('Error fetching customer data:', error);
            const tableBody = document.querySelector('#customerTable tbody');
            const errorRow = document.createElement('tr');
            errorRow.innerHTML = `<td colspan="5">Failed to load customer data: ${error.message}</td>`;
            tableBody.appendChild(errorRow);
          });
</script>
</body>
</html>